package ru.st.selenium;

import java.util.regex.Pattern;
import java.util.concurrent.TimeUnit;
import org.testng.*;
import org.testng.annotations.*;

import static org.junit.Assert.*;
import static org.hamcrest.CoreMatchers.*;
import org.openqa.selenium.*;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.support.ui.Select;

import ru.st.selenium.model.Film;
import ru.st.selenium.model.User;

public class SearchMovie extends ru.st.selenium.pages.TestBase {
	private StringBuffer verificationErrors = new StringBuffer();

	
	@BeforeMethod
	  public void mayBeLogout() {
	    if (app.getUserHelper().isNotLoggedIn()) {
	      return;
	    }
	    app.getUserHelper().logout();
	  }
	  
	  @Test
	  public void searchMovieOK() throws Exception {
	    User user = new User().setLogin("admin").setPassword("admin");
	    app.getUserHelper().loginAs(user);	    
	    
	        
		app.getFilmHelper().search("Bug");	 
		try {
		      assertEquals("Bug", driver.findElement(By.cssSelector("div.title")).getText());
		    } catch (Error e) {
		      verificationErrors.append(e.toString());
		    }
	  }
	  
	  @Test
	  public void searchMovieFailed() throws Exception {
	    User user = new User().setLogin("admin").setPassword("admin");
	    app.getUserHelper().loginAs(user);	    
	    
	        
		app.getFilmHelper().search("Wrong");	
		try {
		      assertEquals("No movies where found.", driver.findElement(By.cssSelector("div.content")).getText());
		    } catch (Error e) {
		      verificationErrors.append(e.toString());
		    }
	  }
	  
	 
}
